package com.jihu.design.behavioral.iterator;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jihu
 * @date 2021/10/12
 */
public abstract class BeautifulMan {

    private List<String> girlFriends = new ArrayList<>();

    void likeYou(String name){
        girlFriends.add(name);
    };

    void sayBye(String name){
        girlFriends.remove(name);
    };

    public Itr getIterator(){
        return new Iterator();
    }

    class Iterator implements Itr{

        private int cursor = 0;//当前指针

        @Override
        public boolean hashNext() {
            return cursor < girlFriends.size();
        }

        @Override
        public String next() {
            String name = girlFriends.get(cursor);
            cursor ++ ;
            return name;
        }

        @Override
        public String firstLove() {
            return girlFriends.get(0);
        }

        @Override
        public String current() {
            return girlFriends.get(girlFriends.size() - 1 );
        }
    }


    interface Itr{
        boolean hashNext();
        String next();
        String firstLove();
        String current();

    }
}
